using System;
using WCell.Constants;
using WCell.RealmServer.Misc;

namespace WCell.RealmServer.Entities
{
    public partial class Character
	{
		/// <param name="character"></param>
		/// <param name="firstLogin">Indicates whether the Character starts a new session or if 
		/// the client re-connected to a Character that was already logged in.</param>
		public delegate void CharacterLoginHandler(Character chr, bool firstLogin);
		public delegate void CharacterLogoutHandler(Character chr);

		#region Login/Logout
		/// <summary>
		/// Is called when the Player logs in or reconnects to a Character that was logged in before and not logged out yet (due to logout delay).
		/// </summary>
		public static event CharacterLoginHandler LoggedIn;
		/// <summary>
		/// Is called before Logout-procedure begins.
		/// </summary>
		public static event CharacterLogoutHandler LoggingOut;

		/// <summary>
		/// Is called after the given Character was saved to DB due to logout (Client is already disconnected when this happens).
		/// Event is not raised in region context and Character is not inside the World map anymore.
		/// </summary>
		public static event CharacterLogoutHandler LoggedOut;
		#endregion

		#region Misc
		/// <summary>
		/// Is called when the given newly created Character logs in the first time.
		/// </summary>
		public static event Action<Character> Created;
		
		/// <summary>
		/// Is called when the given Character gains a new Level.
		/// </summary>
		public static event Action<Character> LeveledUp;
		#endregion

		/// <summary>
		/// Is called right before this Character receives the given <see cref="IDamageAction"/>
		/// </summary>
		public static event AttackHandler HitReceived;

		internal static void NotifyHitReceive(IDamageAction action)
		{
			var evt = HitReceived;
			if (evt != null)
			{
				evt(action);
			}
		}

		/// <summary>
		/// Is called right before this Character delivers the given <see cref="IDamageAction"/>
		/// </summary>
		public static event AttackHandler HitDelivered;

		internal static void NotifyHitDeliver(IDamageAction action)
		{
			var evt = HitDelivered;
			if (evt != null)
			{
				evt(action);
			}
		}
	}
}
